import Rhino.Geometry as rg          #Import Open Nurbs
import rhinoscriptsyntax as rs      #Import RhinoScript
import math

#Get Origin
originPt =  rs.GetPoint()
slabs = []
noSlabs = 30 #Modified by Ben 04.06.11

rs.CurveClosestPoint(
class slab(object):
    normal = rg.Vector3d(0,0,1)
    
    def __init__(self,origin,w,d,h,a):
        #Assign properties to Slab
        self.origin = origin
        self.w = w
        self.d = d
        self.h = h
        self.a = a
        
        #Setup Plane
        self.plane = rg.Plane(origin,slab.normal)
        
    def create(self):
        #Create Open Nurbs Box
        slab = rg.Box(self.plane,self.w,self.d,self.h)
        
        #Rotate Slab
        tMatrix = rg.Transform.Rotation(self.a *(math.pi/180),self.normal,self.origin)
        slab.Transform(tMatrix)
        
        #Draw Box Geometry
        self.corners = slab.GetCorners()
        self.slab2 = rs.AddBox(self.corners)
        
    def delete(self):
        rs.DeleteObject(self.slab2)
        
    def update(self):
        self.delete()
        self.create()

rs.EnableRedraw(False)

for i in range(noSlabs,0,-1):
    #Raise Origin to Next Level
    originPt.Z = originPt.Z + 3
    
    #Adjust Variables
    width = rg.Interval(-5,5)
    depth = rg.Interval(-5,i * .5)
    height = rg.Interval(0,0.2)
    angle = (i+1) * 5
    
    #Create Slab Object
    slabs.append( slab(originPt,width,depth,height, angle) )
    slabs[noSlabs-i].create()

for i in range(noSlabs,1,-1):
    rs.AddLine(slabs[i-1].corners[0],slabs[i-2].corners[0])
    rs.AddLine(slabs[i-1].corners[1],slabs[i-2].corners[1])
    rs.AddLine(slabs[i-1].corners[2],slabs[i-2].corners[2])
    rs.AddLine(slabs[i-1].corners[3],slabs[i-2].corners[3]) 

rs.EnableRedraw(True)